[

    async function( kuo,Context,context){
        Context.headers["content-type"] = 'application/json; charset=UTF-8';
        let LANG = this.LANG();
        let $DATA = Object.assign({},this.$DATA);
       
        let $Security = await Mem.Get("session/"+kuo.sessionid);
        if(! $Security ){
            $Security ={ adminid: 0};
        }
        if(typeof($Security['adminid']) == "undefined" ){
            $Security['adminid'] = 0;
        }
        if($Security['adminid'] < 1){
            $DATA.code = 99;
            $DATA.msg = "Go Login";
            Context.body =JSON.stringify($DATA);
            return ;
        }
        let fan = await Mode("admin").Loginok(kuo,$Security);
        if(fan){
            $DATA.code = fan;
            $DATA.msg = "Error";
            if($Security['adminid'] > 0){
                let $hash = 'safetoken/'+$Security['adminid'];
                $DATA.token = Mode("Tools").Uuid();
                Mem.Set($hash,$DATA.token);
            }
            Context.body = JSON.stringify($DATA);
            return ;
        }
        
        kuo.adminid = $Security['adminid'];
        let $hash = 'safetoken/'+kuo.adminid;
        $DATA.token = Mode("Tools").Uuid();
        Mem.Set($hash,$DATA.token);
        let  $kongzhi = kuo.Path[1]?kuo.Path[1]:"get";

        let  $db = await db('cms_type');
        let  $_GET = kuo.get;
        let  $_POST = kuo.post;
        let  $chushi = true; 
        let  $features = await Kuoplus(kuo.class);
       
        if($kongzhi == 'get'){
            $DATA.data = {};
            $DATA.code = 0;
            let $ID = Mode("Tools").Int($_POST['id']);
            if($ID > 0){
                let $data = await  $db.Where({'id':$ID}).Find();
                if(!$data){
                    $DATA.code = -1;
                    $DATA.msg = LANG.get_no;
                    Context.body = JSON.stringify($DATA);
                    return ;
                }
                $DATA.data = $data;
                $DATA.code = 1;
                $DATA.data['ALLTYPE'] = await this.ADMIN_TYPELIST(0);
                if($DATA.data['ALLTYPE']){
                    $DATA.data.ALLTYPE.unshift({ 'title':"顶级分类",'id':0});
                }else{
                    $DATA.data.ALLTYPE = [{ 'title':"顶级分类",'id':0}];
                }

            }else if($ID == -1){

                let tabltmp = Kuo_MysqlTABLE.TaBle[MYSQLconfig.prefix+"cms_type"];
                if(tabltmp){
                    for(var x in tabltmp){
                        $DATA.data[x] =  tabltmp[x];
                    }
                    $DATA.data['id'] = 0;
                    $DATA.data['off'] = 2;
                }
                $DATA.data['ALLTYPE'] = await this.ADMIN_TYPELIST(0);
                if($DATA.data['ALLTYPE']){
                    $DATA.data.ALLTYPE.unshift({ 'title':"顶级分类",'id':0});
                }else{
                    $DATA.data.ALLTYPE = [{ 'title':"顶级分类",'id':0}];
                }
              
            
            }else{

                $DATA.data.ALLTYPE =[];
                let $fan = await this.ADMIN_TYPELIST(0);
                if($fan){
                    $DATA.data.ALLTYPE = $fan;
                    $DATA.data.ALLTYPE.unshift({ 'title':"创建分类",'id':-1});
                }else{
                    $DATA.data.ALLTYPE = [{ 'title':"创建分类",'id':-1}];
                }
                $DATA.data['内容模版'] ={'':'默认内容neirog'};
                if( isset($features['configure']['内容模版'])){
                    for(var xxx in $features['configure']['内容模版']){
                        let $vv = $features['configure']['内容模版'][xxx];
                        $DATA.data['内容模版'][$vv] = $vv;
                    }
                }
                $DATA.data['列表模版'] ={'':'默认列表list'};
                if( isset($features['configure']['列表模版'])){
                    for(var xxx in $features['configure']['列表模版']){
                        let $vv = $features['configure']['列表模版'][xxx];
                        $DATA.data['列表模版'][$vv] = $vv;
                    }
                }
            }
    
        }else if($kongzhi == 'put'){

            $_POST['name'] = Mode("Tools").Xss($_POST['name']?$_POST['name']:"");
            if($_POST['name'] == ""){
                $DATA.code = -1;
                $DATA.msg = LANG.name_kong;
                Context.body = JSON.stringify($DATA);
                return ;
            }
            let $id = Mode("Tools").Int($_POST['id']?$_POST['id']:0);
            let $data = await $db.Where({id: $id}).Find();
            if(!$data){
                $DATA.code = -1;
                $DATA.msg = LANG.get_no;
                Context.body = JSON.stringify($DATA);
                return ;
            }

            $_POST['xtime'] = Mode("Tools").Time();
            if($_POST['url'] != $data['url'] || $_POST['url'] == ""){
                if($data['url'] != ""){
                   await $db.Where({id: $id}).Update({'url':''});
                }
                let $fanx = await this.ADMIN_FINDURL($_POST['url']);
                if(!$fanx){
                    $_POST['url'] = ($features['configure']['默认前缀']['0']?$features['configure']['默认前缀']['0']: "" )+$id;
                    $fanx = await this.ADMIN_FINDURL($_POST['url']);
                    if(!$fanx){
                        $_POST['url']  = 'type_'+$id;
                    }
                }
            }
            

            if( $_POST['subclass'] != $data['subclass'] ){
                let $fanhui = await this.ADMIN_FINDSUBCLASS($_POST['subclass'],$id);
                if(!$fanhui){
                    $_POST['subclass'] = $data['subclass'];
                }
            }
        
            if($_POST['subclass'] == $id ){
                $_POST['subclass'] = 0;
            }

            if($Security['groups'] > 0){
                $_POST['adminuid'] = kuo.adminid;
            }
            
            $_POST['keywords']= implode(',',$_POST['keywords']);
            $_POST['Expand']= implode(',',$_POST['Expand']);

            let $POSTexpansion = $_POST['expansionform']? $_POST['expansionform']:[];
            $_POST['expansionform']= implode(',',$POSTexpansion);

            if($POSTexpansion){
                let $_POSTexpansionform = [];
                for(var $zzz_ in $POSTexpansion ){
                    let $zzz = $POSTexpansion[$zzz_];
                    let $hx =  explode('-',$zzz);
                    let $key = reset($hx);
                    if(isset($_POST['expansion_'+$key])){
                        if(is_array($_POST['expansion_'+$key])){
                            let $zicihuo = [];
                            for(var $vvv_ in $_POST['expansion_'+$key] ){
                                let $vvv =$_POST['expansion_'+$key][$vvv_];
                                if(is_array($vvv)){
                                    $zicihuo.push(implode('$',  $vvv ));
                                }else{
                                    $zicihuo.push($vvv);
                                }
                            }
                            $_POSTexpansionform.push(implode(',',  $zicihuo ));
                        }else{
                            $_POSTexpansionform.push($_POST['expansion_'+$key]);
                        }
                    }
                }
                $_POST['expansion'] = implode('(_$$_)',$_POSTexpansionform);
            }

            let $fan = await $db.Where({id: $id}).Update($_POST);
            if($fan){
                await Kuolog('adminlog',kuo.adminid,3,{'yuan':$data,'data':$_POST},kuo.func_,kuo.class,kuo.ip);
                $DATA.data = $_POST;
                $DATA.code =1;
                $DATA.msg = LANG.put_ok;
            }else{
                $DATA.code =-1;
                $DATA.msg = LANG.put_no;
            }
    
        }else if($kongzhi == 'add'){

            $_POST['name'] = Mode("Tools").Xss($_POST['name']?$_POST['name']:"");
            if($_POST['name'] == ""){
                $DATA.code = -1;
                $DATA.msg = LANG.name_kong;
                Context.body = JSON.stringify($DATA);
                return ;
            }
            $_POST['keywords']= implode(',',$_POST['keywords']);
            $_POST['Expand']= implode(',',$_POST['Expand']);
            $_POST['url'] = KuoSecurity($_POST['url']);
            let $gengurl = false;
            if($_POST['url'] == "" ){
                $gengurl = true;
            }else {
                let $fanx = await this.ADMIN_FINDURL($_POST['url']);
                if(!$fanx){
                    $gengurl = true;
                }
            }

            let $POSTexpansion = $_POST['expansionform']? $_POST['expansionform']:[];
            $_POST['expansionform']= implode(',',$POSTexpansion);
            if($POSTexpansion){
                let $_POSTexpansionform = [];
                for(var $zzz_ in $POSTexpansion ){
                    let $zzz = $POSTexpansion[$zzz_];
                    let $hx =  explode('-',$zzz);
                    let $key = reset($hx);
                    if(isset($_POST['expansion_'+$key])){
                        if(is_array($_POST['expansion_'+$key])){
                            let $zicihuo = [];
                            for(var $vvv_ in $_POST['expansion_'+$key] ){
                                let $vvv =$_POST['expansion_'+$key][$vvv_];
                                if(is_array($vvv)){
                                    $zicihuo.push(implode('$',  $vvv ));
                                }else{
                                    $zicihuo.push($vvv);
                                }
                            }
                            $_POSTexpansionform.push(implode(',',  $zicihuo ));
                        }else{
                            $_POSTexpansionform.push($_POST['expansion_'+$key]);
                        }
                    }
                }
                $_POST['expansion'] = implode('(_$$_)',$_POSTexpansionform);
            }
            
           
            let $fan =await $db.Insert($_POST);
            if($fan){

                if( $gengurl){
                    $_POST['url'] = ($features['configure']['默认前缀']['0']?$features['configure']['默认前缀']['0']: "" )+$fan;
                    let $fanx = await this.ADMIN_FINDURL( $_POST['url'] );
                    if(!$fanx){
                        $_POST['url']  = 'type_'+$fan;
                    }
                    await $db.Where({'id':$fan}).Update( {'url' :$_POST['url']});
                }
                
                $DATA.code = 1;
                $DATA.msg = LANG.add_ok;
                await Kuolog('adminlog',kuo.adminid,4, $_POST ,kuo.func_,kuo.class,kuo.ip);
            }else{
                $DATA.code = -1;
                $DATA.msg = LANG.add_no;
            }
    
    
        }else if($kongzhi == 'del'){
    
            let $id = Mode("Tools").Int($_POST['id']?$_POST['id']:0);
            if($id < 1){
                Mem.Flush("html/");
                $DATA.code = 1;
                $DATA.msg = 'ok';
                Context.body = JSON.stringify($DATA);
                return ;
            }
            let $data = await $db.Where({id: $id}).Find();
            if(!$data){
                $DATA.code = -1;
                $DATA.msg = LANG.admin_id_no;
                Context.body = JSON.stringify($DATA);
                return ;
            }
            let $fan = await $db.Where({id: $id}).Delete();
            if($fan){
                await this.ADMIN_TYPEDEL($id,kuo.adminid,kuo.func_,kuo.class,kuo.ip);
                await Kuolog('adminlog',kuo.adminid,5, $data ,kuo.func_,kuo.class,kuo.ip);
                $DATA.code = 1;
                $DATA.msg = LANG.del_ok;
            }else{
                $DATA.code = -1;
                $DATA.msg = LANG.del_no;
            }
        }

        Context.body = json_encode($DATA);
    }

]